<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="../css/pintuer.css">
<link rel="stylesheet" href="../css/admin.css">
<script src="../js/jquery.js"></script>
<script src="../js/pintuer.js"></script>
<link rel="stylesheet" type="text/css" href="../simditor/styles/simditor.css" />
<script type="text/javascript" src="../simditor/scripts/module.min.js"></script>
<script type="text/javascript" src="../simditor/scripts/hotkeys.min.js"></script>
<script type="text/javascript" src="../simditor/scripts/uploader.min.js"></script>
<script type="text/javascript" src="../simditor/scripts/simditor.min.js"></script>
</head>
<script type="text/javascript">
	$(function(){
		
		$(".button").click(function(){
			
			if($(".button").text().indexOf("修改")!=-1){
				//alert($(".button").text());
				$(".form-x")[0].action="${ctx }/postType/update";
			}
		});
	})
	function change(e){
		var url = $(e).val();
		$("#url").val(url);
	}
	
	var handleMax = function(obj){
		if(obj.value>=10000){
			alert("你输入的金额超过10000，请重新输入 ！");
			obj.value="";
		}
        //修复第一个字符是小数点 的情况.  
        var first='';  
        if(obj.value !=''&& obj.value.substr(0,1) == '.'){  
            obj.value="";  
        }  	  
        obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
        obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的       
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");  
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数       
        if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额      
            obj.value= parseFloat(obj.value);      
        } 
    };
</script>
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o">
  </span>
  <c:if test="${empty postType}">
  	增加课程管理内容
  </c:if>	
  <c:if test="${!empty postType}">
  	 修改课程管理内容
  </c:if>	
  </strong>
  </div>
  <div class="body-content">
    <form method="post" class="form-x" action="${ctx }/postType/insert" enctype="multipart/form-data">  
    <c:if test="${!empty postType}">
  	  <input type="hidden" value="${postType.id }" name="id">
    </c:if>	
      <div class="form-group">
        <div class="label">
          <label>课程名称：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" required value="${postType.name }" name="name" data-validate="required:课程名称,length#<=30:不能大于10个文字" />
          <div class="tips"></div>
        </div>
      </div>
	  <div class="form-group">
        <div class="label">
          <label>课程图片：</label>
        </div>
        <div class="field">
          <input type="text" disabled="disabled" id="url" name="img" class="input tips" required style="width:25%; float:left;"  value="${postType.image }"  data-toggle="hover" data-place="right"  data-validate="required:课程图片"/>
		  <a class="button bg-blue input-file" href="javascript:void(0);" style="float:left;margin-left:10px;">+ 上传图片<input size="100" type="file" onchange="change(this)" name="file" accept=".jpg,.png,.jpeg" id="image" /></a>
		</div>
      </div> 
	 <div class="form-group">
        <div class="label">
          <label>课程简介：</label>
        </div>
        <div class="field">
          <textarea rows="3"  class="input w50" required name="intro" data-validate="required:课程简介,length#<=150:不能大于50个文字" >${postType.intro }</textarea>
          <div class="tips"></div>
        </div>
      </div>
	<div class="form-group">
        <div class="label">
          <label>课程价格：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" required value="${postType.price }" onkeyup="handleMax(this)" name="price" data-validate="required:课程价格" />
          <div class="tips"></div>
        </div>
      </div>
	  <div class="form-group">
        <div class="label">
          <label>课程说明：</label>
        </div>
        <div class="field">
          <textarea rows="5" class="input" required name="describe" data-validate="required:课程说明,length#<=750:不能大于250个文字" >${postType.describe }</textarea>
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit">
            <c:if test="${!empty postType}">
            	修改
        	</c:if>
         	 <c:if test="${empty postType}">
         	 	增加
         	 </c:if>
           </button>
        </div>
      </div>
    </form>
  </div>
</div>
</body>
</html>